package models;

import java.util.*;
import javax.persistence.*;

import play.Logger;
import play.data.format.*;
import play.data.validation.*;
import controllers.LogSession;
import models.User;
import play.mvc.Http;

public class PaymentForm {

	@Constraints.Required
	@Constraints.Email
	@Formats.NonEmpty
	public String email;

	@Constraints.Required
	@Formats.NonEmpty
	@Constraints.Pattern(value = "[0-9]+", message="Must be numeric")
	public String credit_card;

	@Constraints.Required
	@Formats.NonEmpty
	public String seats;

	@Constraints.Required
	@Formats.NonEmpty
	public String lang;
		
	@Constraints.Required
	public Long session;
	
	@Constraints.Required
	public int points;

	public Long expiry_year;
	public Long expiry_month;

	public String validate() {
	
		if(points>0) {
			String uuid = Http.Context.current().session().get("uuid");
			String username = LogSession.getUsernameFromUUID(uuid);
			
			if(username == null)
				return "Cannot find user. Please try relogging in";
				
			User user = User.findByUser(username);
			
			if(user == null)
				return "Unknown Error";
				
			if(user.points<points)
				return "You don't have enough points";	
		}
		
		return null;
	}


}

